package com.example.demo.dao;


import com.example.demo.pojo.Books;
import com.example.demo.pojo.ClassInfo;
import com.example.demo.pojo.OutBound;
import com.example.demo.pojo.Stock;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface BooksMapper {

    /***********************insert*********************************/

    //1-未出库 0-出库
    int insertBook(Books books);


    //添加库存
    int insertStock(Stock stock);

    //添加图书类别
    @Insert("insert into class_info(class_name) values(#{class_name})")
    int insertClassInfo(ClassInfo classInfo);

    //出库表记录数据
    @Insert("insert into out_in_bound(book_id,out_in_num,out_in_date,out_in_state) values(#{book_id},#{out_in_num},#{out_in_date},#{out_in_state})")
    int insertOutBound(OutBound outBound);


    /***********************update*********************************/



    void updateBooksInfoByBookId(Books books);

    @Update("update book_info set class_id = #{class_id} where book_id =#{book_id}")
    void updateBookClassInfoByBookId(int book_id,int class_id);

    //更新类别信息
    @Update("update class_info set class_name = #{class_name} where class_id = #{class_id}")
    void updateClassInfoByClassid(int class_id,String class_name);

    //更新图书状态
    @Update("update book_info set book_state = #{book_state} where book_id = #{book_id}")
    void updateBookStateByBookId(Books books);

    @Update("update book_info set is_deletestate = #{is_deletestate} where book_id = #{book_id}")
    void updateBookIsdeletestateByBookId(Books books);

    @Update("update book_info set lend_times = lend_times +1 where book_id = #{book_id}")
    void updateBookLendTimesByBookId(int book_id);

    /***********************select*********************************/

    //查询图书类别
    @Select("select * from class_info")
    List<ClassInfo> selAllClassInfos();



    //查询库存表
    @Select("select * from stock where stock_no = #{stock_no}")
    Stock selStockByStockNo(String stock_no);

    //根据book_id查询books
    @Select("select * from book_info where book_id = #{book_id}")
    Books selBooksByBookId(int book_id);

    Books selBooksAndStockByBookId(int book_id);

    List<Books> selLendTimesTop5Book();

    @Select("select * from book_info")
    List<Books> selAllBook();

    Books selBookAndStockByBookId(int book_id);


    List<Books> selAllBooks();



    List<Books> selAllBookAndStock();

    List<Books> selAllBookAndStockByStockId(int stock_id);

    List<Books> selAllBookAndStockByConditions(Books books);


    List<OutBound> selAllOutBound();

    @Select("select count(*) from out_in_bound")
    int selAllOutBoundCount();

}
